module.exports = function(t, e) {
    var r = require("../util"), a = e.history || {}, n = e.document, i = function(t, r) {
        var a;
        e.CustomEvent ? a = new CustomEvent(t, {
            detail: r
        }) : ((a = n.createEvent("HTMLEvents")).initEvent(t, !1, !0), a.detail = r), e.dispatchEvent(a);
    }, o = function(t) {
        var e = a[t];
        "function" == typeof e && (a[t] = function(n, o, c) {
            var s = 1 === arguments.length ? [ arguments[0] ] : Array.apply(null, arguments), u = location.href, h = e.apply(a, s);
            if (!c || "string" != typeof c) return h;
            if (c === u) return h;
            try {
                var l = u.split("#"), p = c.split("#"), y = r.cutUrlSearch(l[0]), f = r.cutUrlSearch(p[0]), v = l[1] && l[1].replace(/^\/?(.*)/, "$1"), S = p[1] && p[1].replace(/^\/?(.*)/, "$1");
                y !== f ? i("historystatechange", f) : v !== S && i("historystatechange", S);
            } catch (d) {
                r.warn("[retcode] error in " + t + ": " + d);
            }
            return h;
        }, a[t].toString = r.createFakeToString(t));
    };
    r.ext(t.prototype, {
        hackHistoryState: function() {
            return this.hasHackedHistoryState ? this : (o("pushState"), o("replaceState"), this.hasHackedHistoryState = !0, 
            this);
        }
    });
};